Public Class OrderStatusUpdateCtrl
    Inherits System.Web.UI.UserControl

#Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub
    Protected WithEvents txtETD As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtDepartureDate As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtVessel As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtETA As System.Web.UI.WebControls.TextBox
    Protected WithEvents chkDocSent As System.Web.UI.WebControls.CheckBox
    Protected WithEvents txtDocSentDate As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtPayReceiveDate As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtInvoiceNo As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtInvoiceDate As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtInvoiceValue As System.Web.UI.WebControls.TextBox
    Protected WithEvents txtCost As System.Web.UI.WebControls.TextBox
    Protected WithEvents chkPayReceive As System.Web.UI.WebControls.CheckBox
    Protected WithEvents lblPONo As System.Web.UI.WebControls.Label
    Protected WithEvents lblPODate As System.Web.UI.WebControls.Label
    Protected WithEvents lblETD As System.Web.UI.WebControls.Label
    Protected WithEvents lblDepartureDate As System.Web.UI.WebControls.Label
    Protected WithEvents lblVessel As System.Web.UI.WebControls.Label
    Protected WithEvents lblETA As System.Web.UI.WebControls.Label
    Protected WithEvents lblDocSent As System.Web.UI.WebControls.Label
    Protected WithEvents lblInvoiceDate As System.Web.UI.WebControls.Label
    Protected WithEvents lblCost As System.Web.UI.WebControls.Label
    Protected WithEvents lblPayReceive As System.Web.UI.WebControls.Label
    Protected WithEvents lblInvoiceNo As System.Web.UI.WebControls.Label
    Protected WithEvents lblInvoiceValue As System.Web.UI.WebControls.Label
    Protected WithEvents lblPercentComplete As System.Web.UI.WebControls.Label
    Protected WithEvents txtPercentComplete As System.Web.UI.WebControls.TextBox
    Protected WithEvents CompareValidator1 As System.Web.UI.WebControls.CompareValidator
    Protected WithEvents ranvPercentCompleted As System.Web.UI.WebControls.RangeValidator
    Protected WithEvents RegularExpressionValidator1 As System.Web.UI.WebControls.RegularExpressionValidator
    Protected WithEvents rqPercentComplete As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents rqETD As System.Web.UI.WebControls.RequiredFieldValidator
    Protected WithEvents Comparevalidator2 As System.Web.UI.WebControls.CompareValidator
    Protected WithEvents Comparevalidator3 As System.Web.UI.WebControls.CompareValidator
    Protected WithEvents Rangevalidator1 As System.Web.UI.WebControls.RangeValidator
    Protected WithEvents custVUniqueInvoiceNo As System.Web.UI.WebControls.CustomValidator

    'NOTE: The following placeholder declaration is required by the Web Form Designer.
    'Do not delete or move it.
    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        'CODEGEN: This method call is required by the Web Form Designer
        'Do not modify it using the code editor.
        InitializeComponent()
    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Put user code to initialize the page here        
        If Not Me.Page.IsPostBack Then
            Me.chkDocSent.Attributes.Add("onclick", "checkStatusChanging('" + Me.ClientID + "')")
            Me.chkPayReceive.Attributes.Add("onclick", "checkStatusChanging('" + Me.ClientID + "')")
        End If

    End Sub

    Private Property OrderStatusID() As Integer
        Get
            Return CInt(ViewState("OrderStatusID"))
        End Get
        Set(ByVal Value As Integer)
            ViewState("OrderStatusID") = Value
        End Set
    End Property


    Public Sub FillData(ByVal OSLastweek As COrderStatus, ByVal OS As COrderStatus)
        Try
            Dim objOrder As New COrder
            objOrder.Load(OS.OrderID)
            lblPONo.Text = objOrder.OrderNumber
        Catch ex As Exception

        End Try

        Me.OrderStatusID = OS.ID

        'lblPONo.Text = OS.OrderID.ToString()
        lblPODate.Text = FormatDate(OS.OrderDate)

        If Not (OSLastweek Is Nothing) AndAlso OSLastweek.ObjectState.Tables(0).Rows.Count > 0 Then
            ' Fill Order status from last week 
            lblPercentComplete.Text = CInt(OSLastweek.PercentCompleted).ToString()
            lblETD.Text = MIMS_WRS.Business.Common.FormatDate(OSLastweek.EstTimeDelivery)
            lblDepartureDate.Text = MIMS_WRS.Business.Common.FormatDate(OSLastweek.DepartureDate)
            lblVessel.Text = OSLastweek.Vessel
            lblETA.Text = MIMS_WRS.Business.Common.FormatDate(OSLastweek.EstTimeArrival)
            If (OSLastweek.DocSent) Then
                lblDocSent.Text = "Sent-" & MIMS_WRS.Business.Common.FormatDate(OSLastweek.DocSentDate)
            Else
                lblDocSent.Text = "Not send"
            End If

            If (OSLastweek.PayReceived) Then
                lblPayReceive.Text = "Paid-" & MIMS_WRS.Business.Common.FormatDate(OSLastweek.PayReceivedDate)
            Else
                lblPayReceive.Text = "Not pay"
            End If
            lblInvoiceNo.Text = OSLastweek.InvoiceNo
            lblInvoiceDate.Text = MIMS_WRS.Business.Common.FormatDate(OSLastweek.InvoiceDate)
            lblInvoiceValue.Text = FormatNumber(OSLastweek.InvoiceValue, 2, , , TriState.False)
            lblCost.Text = OSLastweek.Cost.ToString()
        Else
            lblPercentComplete.Text = "N/A"
            lblETD.Text = "N/A"
            lblDepartureDate.Text = "N/A"
            lblVessel.Text = "N/A"
            lblETA.Text = "N/A"
            lblDocSent.Text = "N/A"

            lblPayReceive.Text = "N/A"
            lblInvoiceNo.Text = "N/A"
            lblInvoiceDate.Text = "N/A"
            lblInvoiceValue.Text = "N/A"
            lblCost.Text = "N/A"
        End If

        ' Fill Order status of this week (if has)
        If (OS.PercentCompletedToNull) Then
            txtPercentComplete.Text = ""
        Else
            txtPercentComplete.Text = CInt(OS.PercentCompleted).ToString
        End If

        txtETD.Text = MIMS_WRS.Business.Common.FormatDate(OS.EstTimeDelivery)
        txtDepartureDate.Text = MIMS_WRS.Business.Common.FormatDate(OS.DepartureDate)
        txtVessel.Text = OS.Vessel
        txtETA.Text = MIMS_WRS.Business.Common.FormatDate(OS.EstTimeArrival)
        If (OS.DocSent) Then
            chkDocSent.Checked = True
        Else
            chkDocSent.Checked = False
        End If
        txtDocSentDate.Text = MIMS_WRS.Business.Common.FormatDate(OS.DocSentDate)
        If (OS.PayReceived) Then
            chkPayReceive.Checked = True
            txtPayReceiveDate.Text = MIMS_WRS.Business.Common.FormatDate(OS.PayReceivedDate)
        Else
            chkPayReceive.Checked = False
        End If

        txtInvoiceNo.Text = OS.InvoiceNo
        txtInvoiceNo.Enabled = MIMS_WRS.Web.Security.IsAdmin
        txtInvoiceDate.Text = MIMS_WRS.Business.Common.FormatDate(OS.InvoiceDate)

        If (OS.InvoiceValueToNull) Then
            txtInvoiceValue.Text = ""
        Else
            txtInvoiceValue.Text = FormatNumber(OS.InvoiceValue, 2, , , TriState.False)
        End If

        If (OS.CostToNull) Then
            txtCost.Text = ""
        Else
            txtCost.Text = FormatNumber(OS.Cost, 2, , , TriState.False)
        End If
    End Sub

    Public Sub UpdateData(ByRef obj As COrderStatus)
        If (txtPercentComplete.Text.Trim().Length > 0) Then
            obj.PercentCompleted = CDec(txtPercentComplete.Text.Trim())
        Else
            obj.PercentCompletedToNull = Nothing
        End If

        If (obj.PrevEstTimeDelivery.Equals(System.DateTime.MinValue)) OrElse (Not (obj.EstTimeDelivery.Equals(CDate(txtETD.Text.Trim())))) Then
            obj.PrevEstTimeDelivery = obj.EstTimeDelivery
        End If

        If txtETD.Text = "" Then
            obj.EstTimeDelivery = Nothing
        Else
            obj.EstTimeDelivery = CDate(txtETD.Text.Trim())
        End If

        If txtDepartureDate.Text = "" Then
            obj.DepartureDate = Nothing
        Else
            obj.DepartureDate = CDate(txtDepartureDate.Text.Trim())
        End If

        obj.Vessel = txtVessel.Text.Trim()

        If txtETA.Text = "" Then
            obj.EstTimeArrival = Nothing
        Else
            If (obj.PrevEstTimeArrival.Equals(System.DateTime.MinValue)) OrElse (Not (obj.EstTimeArrival.Equals(CDate(txtETA.Text.Trim())))) Then
                obj.PrevEstTimeArrival = obj.EstTimeArrival
            End If
            obj.EstTimeArrival = CDate(txtETA.Text.Trim())
        End If

        If (chkDocSent.Checked) Then
            obj.DocSent = True
            obj.DocSentDate = CDate(txtDocSentDate.Text.Trim())
        Else
            obj.DocSent = False
        End If
        If (chkPayReceive.Checked) Then
            obj.PayReceived = True
            obj.PayReceivedDate = CDate(txtPayReceiveDate.Text.Trim())
        Else
            obj.PayReceived = False
        End If
        obj.InvoiceNo = txtInvoiceNo.Text.Trim()
        If txtInvoiceDate.Text = "" Then
            obj.InvoiceDate = Nothing
        Else
            obj.InvoiceDate = CDate(txtInvoiceDate.Text.Trim())
        End If

        If (txtInvoiceValue.Text.Trim().Length > 0) Then
            obj.InvoiceValue = CDec(txtInvoiceValue.Text.Trim())
        Else
            obj.InvoiceValueToNull = Nothing
        End If

        If (txtCost.Text.Trim().Length > 0) Then
            obj.Cost = CDec(txtCost.Text.Trim())
        Else
            obj.CostToNull = Nothing
        End If
    End Sub

    Public Sub ValidateUniqueInvoiceNo(ByVal isUnique As Boolean)
        custVUniqueInvoiceNo.IsValid = isUnique
    End Sub
End Class
